
#include "moveframelesswidget.h"
#include <QMouseEvent>
#include <QPainter>

MoveFramelessWidget::MoveFramelessWidget(QWidget *parent)
    : QWidget(parent)
{
    // setObjectName("frameless_window");
    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
}

MoveFramelessWidget::~MoveFramelessWidget()
{

}

void MoveFramelessWidget::mousePressEvent(QMouseEvent *event)
{
    QPoint mousePos = event->globalPos();
    window_pos_ = this->pos();
    diff_pos_ = mousePos - window_pos_; //鼠标和窗口的相对位移
    QWidget::mousePressEvent(event);
}

void MoveFramelessWidget::mouseMoveEvent(QMouseEvent *event)
{
    QPoint pos = event->globalPos();
    this->move(pos - diff_pos_);
    QWidget::mouseMoveEvent(event);
}

void MoveFramelessWidget::paintEvent(QPaintEvent *event)
{
    QWidget::paintEvent(event);
}
